package com.example.lib;

import com.example.lib.socket.HeadData;
import com.example.lib.socket.Mpoint;
import com.example.lib.socket.MyClientSocket;
import com.example.lib.socket.MyServiceSocket;
import com.example.lib.socket.MySocketData;
import com.example.lib.socket.Mycallback;
import com.example.lib.socket.OcrData;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.util.ArrayList;

public class MyTest {
    public static void main(String[] args) {

       // testPrice();
       // testService();
        //testclient();
        testHead();
    }
    public  static void testHead(){
        HeadData hd=new HeadData();
        hd.dataLong=1000;
        hd.clientId=2000;
        hd.fileNameLong=3000;
        HeadData hd2=new HeadData();
       byte[] bs= MySocketData.getHeadByte(hd);
        hd2=MySocketData.getHeadData(bs);
        System.out.println("client send is false ");

    }
    public static void testclient(){
        MyClientSocket cSocket=new MyClientSocket("192.168.10.101",9000);
        Mycallback call=new Mycallback() {
            @Override
            public void MyCall(OcrData od) {
                if (od.ImgStr!=null){
                    System.out.println("od.ImgStr is "+od.ImgStr);
                }else{

                    System.out.println("od.ImgStr is null");
                }
            }
        };
        cSocket.call=call;
        cSocket.data="123";
        cSocket.start();
    }
    public static void testPrice(){
//          String s1="test1";
//          s1=MySocketData.getSendData(s1);
//        byte[] bs=s1.getBytes();
//        HeadData hd=MySocketData.getHeadData(bs);
//          System.out.println(s1);

    }
    public void test1(){
        String s1="1";
        byte[] a=s1.getBytes();

        OcrData od=new OcrData();
        od.msgId=123;
        od.winHand=1;
        od.orcType=2;
        od.list=new ArrayList<>();
        Mpoint p=new Mpoint();
        p.x=12;
        p.y=12;

        od.list.add(p);
        p=new Mpoint();
        p.x=12;
        p.y=12;

        od.list.add(p);

        // 解析JSON
//        String json = "{\"name\":\"John\", \"age\":30}";
        Gson gson = new Gson();
//        User user = gson.fromJson(json, User.class);
        String json = gson.toJson(od);
        System.out.println(json);


    }

    public static void  testService(){


        MyServiceSocket serSocket;
        serSocket=new MyServiceSocket();
        Mycallback call=new Mycallback() {
            @Override
            public void MyCall(OcrData od) {
                if (od.ImgStr!=null){
                    System.out.println("od.ImgStr");
                }
            }
        };
        serSocket.call=call;
        serSocket.start();
    }
}
